/**
 * 
 */
package vue.desktop;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.cnf.CNF;
import model.cnf.Stat;

/**
 * Show the {@link Stat} of a {@link CNF}.
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class IGDeskCNFStat extends JPanel {
	private static final long	serialVersionUID			= 1L;

	public static final String	DEFAULT_STRING				= "UNKNOW";
	public static final String	DEFAULT_LITERAL_PREFIX		= "#Literal: ";
	public static final String	DEFAULT_UNITCLAUSE_PREFIX	= "#Unit clause: ";
	public static final String	DEFAULT_BINCLAUSE_PREFIX	= "#Binary clause: ";
	public static final String	DEFAULT_AVERAGE_PREFIX		= "Average: ";
	public static final Color	DEFAULT_COLOR				= new Color(176, 224, 230, 100);

	private JLabel				numLiteral;
	private JLabel				numUnitClause;
	private JLabel				numBinaryClause;
	private JLabel				averageNumOfLiteralPerClause;


	/**
	 * Create a {@link IGDeskCNFStat}.
	 * 
	 * @param stat
	 *            stat to show.
	 */
	public IGDeskCNFStat(Stat stat) {
		setLayout(new GridLayout(4, 1));
		setOpaque(false);

		// name
		numLiteral = new JLabel(DEFAULT_LITERAL_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		numLiteral.setOpaque(true);
		numLiteral.setBackground(DEFAULT_COLOR);
		numLiteral.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
		// name.setFont(Font.gFont.BOLD);
		// name.set

		numUnitClause = new JLabel(DEFAULT_UNITCLAUSE_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		numUnitClause.setBackground(DEFAULT_COLOR);
		numUnitClause.setOpaque(true);
		numUnitClause.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));

		numBinaryClause = new JLabel(DEFAULT_BINCLAUSE_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		numBinaryClause.setBackground(DEFAULT_COLOR);
		numBinaryClause.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
		numBinaryClause.setOpaque(true);

		averageNumOfLiteralPerClause = new JLabel(DEFAULT_AVERAGE_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		averageNumOfLiteralPerClause.setBackground(DEFAULT_COLOR);
		averageNumOfLiteralPerClause.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
		averageNumOfLiteralPerClause.setOpaque(true);

		add(numLiteral);
		add(numUnitClause);
		add(numBinaryClause);
		add(averageNumOfLiteralPerClause);

		refresh(stat);

		// setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
		// setBorder(BorderFactory.createLineBorder(Color.BLACK));

	}

	/**
	 * Refresh the information.
	 * 
	 * @param stat
	 *            stat to refresh
	 */
	public void refresh(Stat stat) {

		if (stat.getNumLiteral() != Stat.UNKNOW_VALUE)
			numLiteral.setText(DEFAULT_LITERAL_PREFIX + stat.getNumLiteral());
		else
			numLiteral.setText(DEFAULT_LITERAL_PREFIX + DEFAULT_STRING);

		if (stat.getNumUnitClause() != Stat.UNKNOW_VALUE)
			numUnitClause.setText(DEFAULT_UNITCLAUSE_PREFIX + stat.getNumUnitClause());
		else
			numUnitClause.setText(DEFAULT_UNITCLAUSE_PREFIX + DEFAULT_STRING);

		if (stat.getNumBinaryClause() != Stat.UNKNOW_VALUE)
			numBinaryClause.setText(DEFAULT_BINCLAUSE_PREFIX + stat.getNumBinaryClause());
		else
			numBinaryClause.setText(DEFAULT_BINCLAUSE_PREFIX + DEFAULT_STRING);

		if (stat.getAverageNumOfLiteralPerClause() != Stat.UNKNOW_VALUE)
			averageNumOfLiteralPerClause.setText(DEFAULT_AVERAGE_PREFIX + stat.getAverageNumOfLiteralPerClause());
		else
			averageNumOfLiteralPerClause.setText(DEFAULT_AVERAGE_PREFIX + DEFAULT_STRING);

	}
}
